import { getJobLogList, cleanJobLog } from '@/api/log'

const log = {
  state: {
    logList: [],
    total: 0
  },
  mutations: {
    SET_LOG_LIST: (state, list) => {
      state.logList = list
    },
    SET_LOG_TOTAL: (state, total) => {
      state.total = total
    }
  },
  actions: {
    // 获取任务日志列表
    getJobLogList({ commit }, params) {
      return new Promise((resolve, reject) => {
        getJobLogList(params).then(response => {
          const { data, total } = response.data
          commit('SET_LOG_LIST', data)
          commit('SET_LOG_TOTAL', total)
          resolve(data)
        }).catch(error => {
          reject(error)
        })
      })
    },
    
    // 清理任务日志
    cleanJobLog({ dispatch }, params) {
      return new Promise((resolve, reject) => {
        cleanJobLog(params).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    }
  }
}

export default log
